//
//  SXSXSFeaturedBuyPop.m
//  SXS_iOS
//
//  Created by Angela on 2017/8/17.
//  Copyright © 2017年 com.shaxiaoseng. All rights reserved.
//

#import "XJDPopView.h"
@class shadeinvestView;
@interface MineView : UIView
@property (nonatomic, weak) CALayer *styleLayer;
@property (nonatomic, strong) UIColor *popBackgroundColor;
@end
@interface shadeinvestView : UIView
@end
@interface MineViewController : XJDBaseController
@property (nonatomic, weak)shadeinvestView *styleView;
@end
@interface XJDPopView()<UIGestureRecognizerDelegate>
@property (nonatomic,strong) MineView *containerView;
@property (nonatomic, weak)shadeinvestView *styleView;
@property (nonatomic, assign) BOOL isSelect;
@property (nonatomic, strong) UIButton *chooseBtn;
@property (strong, nonatomic) UIWindow *window;

@end
@implementation XJDPopView
+ (XJDPopView *)shadeInstanceBuyPop{
    static XJDPopView *sharedBuyPop;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedBuyPop=[[XJDPopView alloc]init];
    });
    return sharedBuyPop;
}
#pragma mmark-弹窗消失
- (void)hideAnimated:(BOOL)animated withCompletionBlock:(void(^)())completion {
    [self.styleView removeFromSuperview];
}
#pragma mark-弹出开通银行托管弹窗
-(void)showPopView:(popViewType )popTypeStr{
    [[XJDPopView shadeInstanceBuyPop] showWithPresentView:popTypeStr];
}
#pragma mark-弹出弹窗有动画和无动画
-(void) showWithPresentView :(popViewType )popTypeStr{
    shadeinvestView *styleView = [[shadeinvestView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    styleView.opaque =NO;
    self.styleView = styleView;
    _containerView = [[MineView alloc] initWithFrame:rect(0, 0, ScreenWidth, ScreenHeight)];
    _containerView.styleLayer.backgroundColor=UIColorFromRGB(0x848484).CGColor;
    switch (popTypeStr) {
        case XJDCompleteInformation:
            [self goToPersonInformation];
            break;
            
        default:
            break;
    }
    [self.styleView addSubview:self.containerView];
    
        _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        _window.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
        _window.opaque = NO;
    [self.window.rootViewController.view addSubview:self.styleView];
    [self.window makeKeyAndVisible];

    //    [[UIApplication rootViewController].view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
    //        if ([obj isKindOfClass:[shadeinvestView class]]) {
    //            [obj removeFromSuperview];
    //        }
    //    }];
    //    [[UIApplication rootViewController].view addSubview:self.styleView];
}
/************************完善信息**************************/
-(void)goToPersonInformation{
    UIView *bgView=[[UIView alloc]initWithFrame:rect(0,0,ScreenWidth-realValue6(80),realValue6(396))];
    bgView.userInteractionEnabled=YES;
    bgView.center=_containerView.center;
    bgView.backgroundColor=[UIColor whiteColor];
    bgView.layer.cornerRadius=15;
    bgView.layer.masksToBounds=YES;
    [self.containerView addSubview:bgView];
    UILabel *titleLab=[[UILabel alloc]init];
    titleLab.font=[UIFont systemFontOfSize:realValue6(34)];
    titleLab.textColor=UIColorFromRGB(0xf97a2b);
    titleLab.text=@"温馨提示";
    titleLab.backgroundColor=UIColorFromRGB(0xffe9bf);
    titleLab.textAlignment=NSTextAlignmentCenter;
    titleLab.frame=rect(0,0, bgView.width, realValue6(81));
    [bgView addSubview:titleLab];
    
    UILabel *noticeLab=[[UILabel alloc]init];
    noticeLab.font=[UIFont fontWithName:XJDFont size:realValue6(36)];
    noticeLab.textColor=UIColorFromRGB(0x626262);
    noticeLab.numberOfLines=2;
    noticeLab.textAlignment=NSTextAlignmentCenter;
    NSMutableParagraphStyle  *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle  setLineSpacing:realValue6(27)];
    NSString *testString=@"您当前还未完善个人资料\n完善后即可申请贷款。";
    NSMutableAttributedString  *setString = [[NSMutableAttributedString alloc] initWithString:testString];
    [setString  addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [testString length])];
    [noticeLab  setAttributedText:setString];
    [noticeLab sizeToFit];
    noticeLab.frame=rect(0,titleLab.bottom+realValue6(38), bgView.width,noticeLab.height);
    [bgView addSubview:noticeLab];
    
    UIButton*finishIfoBtn=[[UIButton alloc]init];
    finishIfoBtn.layer.cornerRadius=realValue6(92);
    finishIfoBtn.layer.borderWidth=1;
    finishIfoBtn.layer.borderColor=UIColorFromRGB(0xffe9bf).CGColor;
    finishIfoBtn.frame=rect(realValue6(102),noticeLab.bottom+realValue6(50),bgView.width-realValue6(204),realValue6(90));
    [finishIfoBtn setTitle:@"完善资料" forState:UIControlStateNormal];
    [finishIfoBtn setTitleColor:UIColorFromRGB(0xffe9bf) forState:UIControlStateNormal];
    finishIfoBtn.titleLabel.font=[UIFont fontWithName:XJDFont size:realValue6(36)];
    [finishIfoBtn addTarget:self action:@selector(finishInformationBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:finishIfoBtn];
    
}
#pragma mark-完善信息
- (void)finishInformationBtnClick:(UIButton *)btn {
    [[XJDPopView shadeInstanceBuyPop] hideAnimated:NO withCompletionBlock:nil];
}
@end
/***********************************************************************************************/
@implementation MineViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    shadeinvestView *styleView = [[shadeinvestView alloc] initWithFrame:self.view.bounds];
    styleView.opaque =NO;
    [self.view addSubview:styleView];
    self.styleView = styleView;
}
//- (UIStatusBarStyle)preferredStatusBarStyle {
////    return [UIApplication currentViewController].preferredStatusBarStyle;
//}
@end
@implementation MineView
- (instancetype)initWithFrame:(CGRect)frame {
    self= [super initWithFrame:frame];
    if(!self) {
        CALayer *styleLayer = [[CALayer alloc] init];
        styleLayer.cornerRadius =4;
        styleLayer.shadowColor= [[UIColor whiteColor] CGColor];
        styleLayer.shadowOffset = CGSizeMake(0,0);
        styleLayer.shadowOpacity =0.5;
        styleLayer.borderWidth =1;
        styleLayer.borderColor = [[UIColor whiteColor] CGColor];
        styleLayer.frame = CGRectInset(self.bounds,12,12);
        [self.layer addSublayer:styleLayer];
        self.styleLayer = styleLayer;
    }
    return self;
}
- (void)setPopBackgroundColor:(UIColor *)popBackgroundColor {
    if(_popBackgroundColor != popBackgroundColor){
        _popBackgroundColor = popBackgroundColor;
        self.styleLayer.backgroundColor = [popBackgroundColor CGColor];
    }
}
@end
@implementation shadeinvestView
-(void)drawRect:(CGRect)rect{
    CGContextRef context = UIGraphicsGetCurrentContext();
    [[UIColor colorWithWhite:0 alpha:0.55] set];
    CGContextFillRect(context,self.bounds);
}
@end
